﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pryTransfinter.Reportes;
using System.Data.SqlClient;
using System.Configuration;

namespace pryTransfinter.Transaciones
{
	public partial class ReporteVisualizador : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
            if (!IsPostBack)
            {
                if (Session["id_reporte"]==null)
            {

            }
            else
            {
               string sql =(string)Session["id_reporte"];
               this.MostraReporte(sql);
            }
            }
            
		}

        private void MostraReporte(string sql)
        {
            try
            {
                rptTransferencia myreport = new rptTransferencia();
                SqlConnection scSqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionReportesTransfinter"].ToString());
                SqlCommand scSqlCommand = new SqlCommand();
                
                String Query1 = sql;
                if (Query1 == string.Empty)
                {
                    return;
                }
                SqlDataAdapter adapter = new SqlDataAdapter(Query1, scSqlConnection);

                dsTransfinter Ds = new dsTransfinter();

                // here my_dt is the name of the DataTable which we 
                // created in the designer view.
                adapter.Fill(Ds, "ReportesTransferencia");

                if (Ds.Tables[0].Rows.Count == 0)
                {
                    popupOK.HeaderText = "Mensaje";
                    popupOK.ShowOnPageLoad = true;
                    lblmensaje.Text = "No existe ningun registro en la grilla.";
                    return;
                }

                // Setting data source of our report object
                myreport.SetDataSource(Ds);

                myreport.SetDataSource(Ds.Tables[0]);
                CrystalReportViewer1.ReportSource = myreport;
                CrystalReportViewer1.DataBind();
                CrystalReportViewer1.Visible = true;
                myreport.Refresh();
                
            }
            catch (Exception ex)
            {
                popupOK.HeaderText = "Mensaje";
                popupOK.ShowOnPageLoad = true;
                lblmensaje.Text = ex.Message;
                return;
            }
        }
	}
}